Fix Core Data model duplication test flakiness - #25932
Merged
Merged
Conversation
The unit tests share one process, and Core Data registers every loaded model's entities in a process-global class-to-entity table. Loading a historical schema version alongside the current one leaves two entity descriptions claiming the same NSManagedObject subclass, so +[X entity] can no longer resolve uniquely and crashes unrelated Core Data tests depending on execution order. Reset a loaded historical model's entity classes to the generic NSManagedObject so it never claims the concrete subclasses. The migration tests only reach their data by entity name and key-value coding, so they keep working.
Move currentObjectModel to a public extension so callers (including tests) can reuse the single process-wide model instance instead of loading a second copy of the same schema, which would register duplicate entity-to-class mappings.
createContext defaulted to a freshly merged copy of the current model, adding a second registration of the current schema's NSManagedObject subclasses to Core Data's process-global class-to-entity table and making unrelated tests crash depending on execution order. Use the shared ContextManager.currentObjectModel instead, and neutralize the entity classes of the older model versions the tests load on purpose so they no longer register duplicate concrete subclasses either.
It only covered migrations between the legacy model versions 103 and 104.
crazytonyli
marked this pull request as ready for review
August 24, 2026 03:48
crazytonyli
enabled auto-merge
August 24, 2026 03:48
Contributor
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 33901 | |
| Version | PR #25932 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 62a74d9 | |
| Installation URL | 5mlg079n75o9g |
Contributor
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 33901 | |
| Version | PR #25932 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 62a74d9 | |
| Installation URL | 0ucugq3njukvg |
jkmassel
approved these changes
Aug 24, 2026
pull Bot
pushed a commit
to kliu/WordPress-iOS
that referenced
this pull request
Aug 26, 2026
…mobile#25941) The test built its context from NSManagedObjectModel.mergedModel(from: [Bundle.main]), loading a second copy of the current schema. Every loaded model registers its entities in Core Data's process-global class-to-entity table, so this left two entity descriptions claiming ReaderPost, Blog, and the other subclasses. When a later test in the same process saved, Core Data's change processing hit the ambiguity and crashed with "-[__NSCFSet addObject:]: attempt to insert nil", failing unrelated tests depending on execution order. Use ContextManager.forTesting(), which reuses the single process-wide current model, and pass that stack straight to SharedDataIssueSolver. This completes the deduplication started in wordpress-mobile#25932, which covered DataMigratorTests but not this call site.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


The migration tests load previous versions of Core Data models, which lead to the same Core Data type names (
Blog,Post, etc) can be resolved is mapped to different in-memory representation.This PR made two main changes:
neutralizingEntityClassesto avoid mapping multiple Core Data type names. This function is duplicated in different modules, because it's small and narrow enough that I feel it's an overkill to share it.